home *** CD-ROM | disk | FTP | other *** search
/ NetNews Offline 2 / NetNews Offline Volume 2.iso / news / comp / lang / c-part1 / 6374 < prev    next >
Encoding:
Text File  |  1996-08-05  |  2.4 KB  |  122 lines

  1. Path: news.iadfw.net!usenet
  2. From: alpet@airmail.net (Adam Peterson)
  3. Newsgroups: comp.lang.c
  4. Subject: Re: Help-Assignment2// This time I am posting the code!!!Thanx
  5. Date: Sat, 24 Feb 1996 09:02:39 GMT
  6. Organization: customer of Internet America
  7. Message-ID: <4gmdb3$c3p@news-f.iadfw.net>
  8. References: <312e8912.8777775@news.planet.net>
  9. NNTP-Posting-Host: dal19-06.ppp.iadfw.net
  10. X-Newsreader: Forte Free Agent 1.0.82
  11.  
  12. >The program below runs and does the specifed tasks but is not in
  13. >function prototype form. Any Idea's on passing the array values to
  14. >these functions????
  15.  
  16. Code below run on pc with MSC...
  17. Adam
  18.  
  19. Note 2 different styles of pointer use in the three functions...
  20.  
  21.  
  22. #include<stdio.h>
  23.  
  24.  
  25. void CalcMax(float *fArray, int amount);
  26. void CalcMin(float *fArray, int amount);
  27. void CalcAvg(float *fArray, int amount);
  28.  
  29.  
  30. void CalcMax(float *fArray, int amount)
  31. {
  32. float max;
  33. float *fTemp;
  34. int i;
  35.                                   /* max value calculation*/
  36. fTemp = fArray;
  37. max = *fTemp;
  38.  
  39. for (i = 1; i < amount;i++)    // arrays start at zero in c 
  40. {
  41.     if (*fTemp>max)
  42.         max=*fTemp;
  43.     fTemp++;
  44. }
  45.         
  46.      
  47. printf("\n\nThe Max Value of all entered is: %5.1f\n",max);
  48.  
  49. }
  50.  
  51. void CalcMin(float *fArray, int amount)
  52. {
  53. float min;
  54. int i;
  55.  
  56. min=*fArray;                                   /* min value
  57. calculation */
  58.  
  59. for (i = 1; i <amount; i++)
  60.     if (*(fArray + i) < min)
  61.           min=*(fArray + i);
  62.  
  63. printf("\n\nThe Min Value of all entered is: %5.1f\n",min);
  64.  
  65. }
  66.  
  67.  
  68. void CalcAvg(float *fArray, int amount)
  69. {
  70.  
  71. float avg;
  72. int i;
  73.  
  74.                                /* average value calculation */
  75.  
  76. for (i = 0; i < amount; i++)
  77.     avg += *(fArray + i);
  78.     
  79. printf("\n\nThe Avg Value of all entered is: %6.2f\n",avg/amount);
  80.  
  81. }
  82.        
  83.        
  84.  
  85. main()
  86. {
  87.  
  88. float A[100];
  89. int amount;
  90. int        i;            // have a problem using 'total' as an incrementing
  91. counter
  92.                     // plus, a counter for an array shouldn't be float
  93.  
  94.  
  95. printf("  This Program accepts values from the user up to\n"
  96.        "  a maximum 100 and calculates the high, low and \n"
  97.        "  average of the total values entered.\n");
  98.  
  99. printf("\nPlease enter the amount of values you wish to use ?\n\n");
  100. scanf("%i",&amount);
  101.  
  102. for ( i = 0; i <= amount-1; i++)
  103.  
  104.     { printf(" \nPlease enter a number : ");
  105.       scanf("%f",&A[i]);}
  106.                               
  107.  
  108. printf(" \n\nThe values you have entered are as follows\n\n");
  109.  
  110. for (i = 0; i < amount; i++)
  111.  
  112. printf("%6.1f",A[i]); 
  113.  
  114. CalcMax(A, amount);
  115. CalcMin(A, amount);
  116. CalcAvg(A, amount);
  117.  
  118.  
  119. return 0;
  120. }
  121.  
  122.